package com.study.controller;

import com.study.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("user")
public class UserController {

    @GetMapping("findAll")
    public String findAll(HttpServletRequest request, Model model) {
        System.out.println("查询所有");

        //显示单数据
        model.addAttribute("name", "小张");
        //显示有标签的单数据
        model.addAttribute("username", "<a href=''>小张张</a>");
        ////显示1个对象
        model.addAttribute("user", new User("21", "小张", 26, new Date()));
        ////显示多条数据
        List<User> users = Arrays.asList(
                new User("22", "小张123", 23, new Date())
                , new User("23", "小张456", 25, new Date()));

        model.addAttribute("users", users);

        return "index"; //逻辑名  classpath:/templates/逻辑名.html
    }
}